<?php
session_start();

include '../conexao.php';

/*
 * Mostra o formulário de alteração dos dados do paciente
 */
if (isset($_GET['recId']))
{
	/*
	 * Consulta o recibo.
	 */
	$rs = mysql_query("SELECT `RECIBO`.`PACIENTE_ID_PACIENTE`, `RECIBO`.`DESPESA_ID_DESPESA`, `RECIBO`.`DATA_RECIBO`, `RECIBO`.`OBSERVACAO`, `RECIBO`.`VALOR`, `PACIENTE`.`NOME` FROM `RECIBO`, `PACIENTE` WHERE `ID_RECIBO` = " . $_GET['recId'] . " AND `PACIENTE_ID_PACIENTE` = `ID_PACIENTE` ")
		or die("ERRO no comando SQL:" . mysql_error());

	$arrayFields = mysql_fetch_array($rs);

	$idPac = $arrayFields['PACIENTE_ID_PACIENTE'];
	$idDesp = $arrayFields['DESPESA_ID_DESPESA'];
	$dataRec = $arrayFields['DATA_RECIBO'];
	$obs = $arrayFields['OBSERVACAO'];
        $valorDesp = $arrayFields['VALOR'];
        $nomePac = $arrayFields['NOME'];
        
	$rs = mysql_query("SELECT `TIPO_DESPESA`.`DESCRICAO` FROM `DESPESA`, `TIPO_DESPESA` WHERE `ID_DESPESA` = " . $idDesp . " AND `TIPO_DESPESA_ID_TIPO_DESPESA` = `ID_TIPO_DESPESA` ")
		or die("ERRO no comando SQL:" . mysql_error());

	$arrayFields = mysql_fetch_array($rs);

	$despesa = $arrayFields['DESCRICAO'];
}
?>
<?php
	if($_GET['acao']=='novo') {
		$proximaAcao='inserir';
                $dataRec = date("d/m/Y");
                $idPac = $_GET['pacId'];
                $idDesp = $_GET['despId'];
        }
	else
		$proximaAcao='atualizar';
?>
<form name="cadRec" id="cadRec" action="recibo/acao.php" onsubmit="return validateForm(this)" method="POST">
	<input type="hidden" name="acao" value="<?=$proximaAcao?>">
	<input type="hidden" name="recId" value="<?=$_GET['recId']?>">
	<input type="hidden" name="idDesp" value="<?=$idDesp?>">
	<input type="hidden" name="idPac" value="<?=$idPac?>">
	<table align="left" cellpadding="2" cellspacing="5">
	<tr>
		<td>
			<table align="left" cellpadding="2" cellspacing="5">
				<tr>
					<td class="abutton">
						<a href="javascript:void(1);" onclick="javascript:carregaAjax('page', 'recibo/listaRecibo.php?despId=<?=$idDesp?>&pacId=<?=$idPac?>');">Voltar</a>
						| <a href="javascript:void(1);" onclick="submitForm(document.forms['cadRec'],'<?=$proximaAcao?>');">Salvar</a>
						<?php if (isset($_GET['recId'])) {?>
              | <a href="javascript:void(1);" onclick="window.open('recibo/recibo.php?recId=<?=$_GET['recId']?>&valor=<?=$valorDesp?>&nome=<?=$nomePac?>&despesa=<?=$despesa?>', 'Recibo', 'status=0,location=0,menubar=1,toolbar=0,resizable=1,scrollbars=1')">Imprimir</a>
            <?php }?>
          </td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table class="tableBorderCad" frame="hsides" align="left" cellpadding="2" cellspacing="5">
				<tr>
					<td colspan="4"><b>Data Recibo:</b><br>
					<input type="text" name="dataRec" onClick="show_calendar('cadRec.dataRec');"  value="<?=$dataRec?>"  maxlength="10" />
					</td>
				</tr>
				<tr>
					<td colspan="4"><b>Valor:</b><br>
					<input type="text" name="valorDesp" value="<?=$valorDesp?>" onkeypress="mascara(this,soValor)" maxlength="10" />
					</td>
				</tr>
				<tr>
					<td colspan="4">
						Observa&ccedil;&otilde;es:<br>
<textarea style="width: 80%" rows="5" cols="45" name="obs">
<?=trim($obs)?>
</textarea>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td>
			<table align="left" cellpadding="2" cellspacing="5">
				<tr>
					<td class="abutton">
						<a href="javascript:void(1);" onclick="javascript:carregaAjax('page', 'recibo/listaRecibo.php?despId=<?=$idDesp?>&pacId=<?=$idPac?>');">Voltar</a>
						| <a href="javascript:void(1);" onclick="submitForm(document.forms['cadRec'],'<?=$proximaAcao?>');">Salvar</a>
						<?php if (isset($_GET['recId'])) {?>
              | <a href="javascript:void(1);" onclick="window.open('recibo/recibo.php?recId=<?=$_GET['recId']?>&valor=<?=$valorDesp?>&nome=<?=$nomePac?>&despesa=<?=$despesa?>', 'Recibo', 'status=0,location=0,menubar=1,toolbar=0,resizable=1,scrollbars=1')">Imprimir</a>
            <?php }?>
					</td>
				</tr>
			</table>
		</td>
	</tr>
        </table>
</form>
